package com.briup.es.web.controller;

import com.briup.es.config.response.Result;
import com.briup.es.domain.dto.OrderPayDto;
import com.briup.es.domain.dto.PaySuccessDto;
import com.briup.es.service.OrderPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "订单支付模块")
@RestController
@RequestMapping("/order")
public class OrderPayController {

    @Resource
    private OrderPayService orderPayService;

    @ApiOperation("支付订单")
    @PutMapping("/pay")
    public Result<?> pay(@Valid @RequestBody OrderPayDto payDto) {
        String result = orderPayService.pay(payDto);
        return Result.success(result)
                .apply("支付成功");
    }

    @ApiOperation("支付成功，修改订单状态")
    @PutMapping("/paySuccess")
    public Result<?> paySuccess(@Valid @RequestBody PaySuccessDto paySuccessDto) {
        orderPayService.paySuccess(paySuccessDto);
        return Result.success();
    }
}
